import 'package:flutter/material.dart';
import 'package:flutter_blog_manage_study/base/get/get_common_view.dart';
import 'package:flutter_blog_manage_study/res/r.dart';
import 'package:flutter_blog_manage_study/res/strings.dart';
import 'package:flutter_blog_manage_study/ui/page/login/login_controller.dart';
import 'package:flutter_blog_manage_study/widget/edit_widget.dart';
import 'package:flutter_blog_manage_study/widget/logo_name_widget.dart';
import 'package:flutter_blog_manage_study/widget/tool_bar.dart';
import 'package:get/get.dart';

/// * 作者: Tao
/// * 日期: 2024/3/22
/// * 时间: 14:21
/// * 描述:
class LoginPage extends GetCommonView<LoginController> {
  const LoginPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      resizeToAvoidBottomInset: false, // 防止键盘弹出时挤压布局
      body: Container(
        width: double.infinity,
        height: double.infinity,
        decoration: const BoxDecoration(
            // 背景图片
            image: DecorationImage(
                image: AssetImage(R.assetsImagesLoginBackground),
                fit: BoxFit.cover)),
        child: Column(
          children: [
            /// 顶部工具栏
            _buildToolBar(),

            /// logo及app名称
            _buildLogoNameWidget(),

            /// 账户名输入框
            _buildAccountEditWidget(),

            /// 密码输入框
            _buildPasswordEditWidget(),
          ],
        ),
      ),
    );
  }

  /// 顶部工具栏构建
  _buildToolBar() {
    return const ToolBar(
      backColor: Colors.white,
      backgroundColor: Colors.transparent,
    );
  }

  /// logo及app名称控件构建
  _buildLogoNameWidget() {
    return const LogoNameWidget();
  }

  /// 账户名输入框构建
  _buildAccountEditWidget() {
    return EditWidget(
      leftIconWidget: const Icon(
        Icons.perm_identity,
        color: Colors.white,
      ),
      rightIconWidget: const Icon(
        Icons.search,
        color: Colors.white,
      ),
      rightIconOnTap: () {
        debugPrint("点击了右边图标");
      },
      hintText: Strings.loginAccountNameHint.tr,
      onChanged: (text) => controller
        ..account = text
        ..update(),
    );
  }

  /// 密码输入框构建
  _buildPasswordEditWidget() {
    return EditWidget(
      leftIconWidget: const Icon(Icons.lock_open, color: Colors.white),
      hintText: Strings.loginAccountPwdHint.tr,
      passwordType: true,
      onChanged: (text) => controller
        ..password = text
        ..update(),
    );
  }
}
